/*
 * DrawableFactory.cpp
 *
 *  Created on: 24/05/2014
 *      Author: javier
 */

#include "DrawableFactory.h"
#include "BombermanView.h"
#include "StaticView.h"
#include "BombView.h"
#include "ZoombieView.h"
#include "PlantView.h"
#include "ExplosionView.h"

DrawableFactory::DrawableFactory(SDLWindow* window) {
	this->window = window;
	std::string resDir = properties.getProperty("res_dir");
	std::string textureName = resDir + "ground.jpg";
	ground = window->loadTexture(textureName);
	textureName = resDir + "sprites4.png";
	bombermanSprites = window->loadTexture(textureName);
	textureName = resDir + "bomb.png";
	bombSprites = window->loadTexture(textureName);
	textureName = resDir + "box.jpg";
	box = window->loadTexture(textureName);
	textureName = resDir + "metal.jpg";
	metal = window->loadTexture(textureName);
	textureName = resDir + "zombie.png";
	zombie = window->loadTexture(textureName);
	textureName = resDir + "plant.png";
	plant = window->loadTexture(textureName);
	textureName = resDir + "spawn_bomberman.jpg";
	bombermanSpawn = window->loadTexture(textureName);
	textureName = resDir + "spawn_zombie.jpg";
	zombieSpawn = window->loadTexture(textureName);
	textureName = resDir + "explosion.png";
	explosion = window->loadTexture(textureName);
}

Drawable* DrawableFactory::create(Positionable* object) {
	ModelObject type = object->getModelObjectType();
	if (type == BOMBERMAN_WHITE) {
		return new BombermanView(window, bombermanSprites, object, WHITE);
	} else if (type == BOMBERMAN_BLACK) {
		return new BombermanView(window, bombermanSprites, object, BLACK);
	} else if (type == BOMBERMAN_RED) {
		return new BombermanView(window, bombermanSprites, object, RED);
	} else if (type == BOMBERMAN_PURPLE) {
		return new BombermanView(window, bombermanSprites, object, PURPLE);
	} else if (type == BOMBERMAN_GREEN) {
		return new BombermanView(window, bombermanSprites, object, GREEN);
	} else if (type == BOMBERMAN_YELLOW) {
		return new BombermanView(window, bombermanSprites, object, YELLOW);
	} else if (type == GROUND) {
		return new StaticView(window, ground, object);
	} else if (type == BOMB) {
		return new BombView(window, bombSprites, object);
	} else if (type == BOX) {
		return new StaticView(window, box, object);
	} else if (type == METAL) {
		return new StaticView(window, metal, object);
	} else if (type == ZOMBIE_BLUE) {
		return new ZoombieView(window, zombie, object, Z_BLUE);
	} else if (type == ZOMBIE_GREEN) {
		return new ZoombieView(window, zombie, object, Z_GREEN);
	} else if (type == ZOMBIE_RED) {
		return new ZoombieView(window, zombie, object, Z_RED);
	} else if (type == PLANT) {
		return new PlantView(window, plant, object);
	} else if (type == BOMBERMAN_SPAWN) {
		return new StaticView(window, bombermanSpawn, object);
	} else if (type == ZOMBIE_SPAWN) {
		return new StaticView(window, zombieSpawn, object);
	}
	return NULL;
}

DrawableFactory::~DrawableFactory() {
	SDL_DestroyTexture(bombermanSprites);
	SDL_DestroyTexture(bombSprites);
	SDL_DestroyTexture(box);
	SDL_DestroyTexture(metal);
	SDL_DestroyTexture(ground);
	SDL_DestroyTexture(zombie);
	SDL_DestroyTexture(plant);
	SDL_DestroyTexture(bombermanSpawn);
	SDL_DestroyTexture(zombieSpawn);
	SDL_DestroyTexture(explosion);
}

Drawable* DrawableFactory::createExplosion(Positionable* object) {
	return new ExplosionView(window, explosion, object);
}
